#!/usr/bin/env python3

from itertools import permutations

def checkpan(var):
    used = set()
    needed = set(range(1,len(str(var))+1))
    for char in str(var):
        if int(char) in needed:
            if int(char) in used:
                return False
            else:
                needed.remove(int(char))
                used.add(int(char))
    if len(needed) is 0:
        return True
    else:
        return False

def ltoi(list):
    a = ''
    for l in list:
        a += str(l)
    return int(a)
    
def getpan(n):
    for x in permutations(range(1,n+1)):
        yield ltoi(x)
    
def checkprime(num):
    for x in range(2,int(num**.5+1)):
        if num % x == 0:
            return False
    return True

answer = 0

for n in range(9,1,-1):
    for x in getpan(n):
        if checkprime(x) and x > answer:
            answer = x
            
print(answer)